package com.bdqn.web;

import com.bdqn.pojo.SysUser;
import com.bdqn.service.SysUserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * SysUserController
 *
 * @author LILIBO
 * @since 2025/3/19
 */
@RestController
@RequestMapping("/user")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    /**
     * 新增用户
     */
    @PostMapping("/add")
    public boolean add(@RequestBody SysUser sysUser) {
        return sysUserService.save(sysUser);
    }

    /**
     * 修改用户
     */
    @PutMapping("/upd")
    public boolean upd(@RequestBody SysUser sysUser) {
        return sysUserService.updateById(sysUser);
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/del")
    public boolean del(Long usrId) {
        return sysUserService.removeById(usrId);
    }

    /**
     * 获取用户列表
     */
    @GetMapping("/list")
    public List<SysUser> list(@RequestParam(required = false) String usrName, @RequestParam(required = false) Long usrRoleId) {
        return sysUserService.getByUsrNameAndRoleId(usrName, usrRoleId);
    }

}
